package ua.org.groovy.gs.botworld;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;

import ua.org.groovy.gs.core.Agent;
import ua.org.groovy.gs.core.AgentContext;
import ua.org.groovy.gs.core.World;

public class Botworld extends World{	
	private Bot bot;
	
	private int worldHeight;

	private int worldWidth;
	
	
	public class Context extends AgentContext {

		public Object getProperty(String name) {
			if (name.equals("worldHeight"))
				return getWorldHeight();
			else if (name.equals("worldWidth"))
				return getWorldWidth();
			return null;
		}

		public void setProperty(String name, Object property) {
			
		}
		
	}
	
	public Botworld() {
		bot = new Bot();
	}
	
	public void update(int deltaMillis) {
		bot.update(deltaMillis);
	}
	
	public void draw(Graphics2D g) {
		drawGrid(g);
		drawObstacle(g);
		bot.draw(g);
	}

	public AgentContext getAgentContext(Agent a) {
		return new Botworld.Context();
	}
	
	public void updateDefaultController(String scriptText) {
		bot.setController(scriptText);
	}
	
	private void drawObstacle(Graphics g) {
		g.setColor(new Color(0x007575));
		g.fillRect(130, 70, 40, 10);
	}
		
	private void drawGrid(Graphics g) {
		g.setColor(new Color(0x006600));
		for (int i = 0; i < 15; i++) {
			g.drawLine(0, 50*i, 500, 50*i);
		}
		for (int i = 0; i < 15; i++) {
			g.drawLine(50*i, 0, 50*i, 300);
		}
	}

	public void setWorldHeight(int worldHeight) {
		this.worldHeight = worldHeight;
	}

	public int getWorldHeight() {
		return worldHeight;
	}

	public void setWorldWidth(int worldWidth) {
		this.worldWidth = worldWidth;
	}

	public int getWorldWidth() {
		return worldWidth;
	}
}